/************************************************************************

								Heroes IV
					  Copyright 2002, The 3DO Company

	------------------------------------------------------------------
  						 combat_area_shader_data.h

	$Header:  $

	$NoKeywords: $

 ************************************************************************/

#if !defined( COMBAT_AREA_SHADER_DATA_H_INCLUDED )
#define COMBAT_AREA_SHADER_DATA_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <assert.h>
#include <limits>
#include <vector>
#include "isometric_map.h"
#include "map_point.h"
#include "map_rect.h"
#include "sized_int_types.h"

// -----------------------------------------------------------------------
// Data for t_combat_area_shader. Pass this structure to 
// t_combat_area_shader::set_shading() to define which tiles should be
// shaded which colors
// -----------------------------------------------------------------------
class t_combat_area_shader_data
{
	public:
		t_combat_area_shader_data( int battlefield_size );

		t_uint8								add_to_palette( t_uint16 color ); 		// Add color to palette, returns the index
		
		t_map_rect_2d const &				get_bounding_rect() const;
		std::vector< t_uint16 > const &		get_palette() const;
		t_isometric_map< t_uint8 > const &	get_tile_data() const;

		bool								is_empty() const;

		void								set_tile_to_color( t_map_point_2d const & point, t_uint8 palette_index );
		void								set_tile_to_transparent( t_map_point_2d const & point );
		
		void								reset(); // Reset palette and tiles

	private:
		t_map_rect_2d				m_bounding_rect; // Bounding rect of non-transparent tiles
		std::vector< t_uint16 >		m_palette; // 0 is reserved for transparent
		t_isometric_map< t_uint8 >  m_tile_data;   // Palette entry for each tile

		static t_map_rect_2d const  k_empty_rect; // Used for all-empty bounding rects
};

// Add color to palette, returns the index
inline t_uint8 t_combat_area_shader_data::add_to_palette( t_uint16 color )
{
	assert( m_palette.size() < std::numeric_limits< t_uint8 >::max() );
	m_palette.push_back( color );
	return m_palette.size() - 1;
}
		
inline t_map_rect_2d const & t_combat_area_shader_data::get_bounding_rect() const
{
	return m_bounding_rect;
}

inline std::vector< t_uint16 > const & t_combat_area_shader_data::get_palette() const
{
	return m_palette;
}

inline t_isometric_map< t_uint8 > const & t_combat_area_shader_data::get_tile_data() const
{
	return m_tile_data;
}

inline bool t_combat_area_shader_data::is_empty() const
{
	return m_bounding_rect == k_empty_rect;
}


inline void t_combat_area_shader_data::set_tile_to_transparent( t_map_point_2d const & point )
{
	assert( m_tile_data.is_valid( point ) );
	m_tile_data.get( point ) = 0;
}
		


#endif // COMBAT_AREA_SHADER_DATA_H_INCLUDED